#! /usr/bin/env python
# coding=utf-8

from Bio import SeqIO
import os
import shutil
import argparse
import sys
from argparse import RawTextHelpFormatter


parser = argparse.ArgumentParser(
    description='''
    建立一个文件夹 将一个fasta文件 中的每个序列作为一个文件 放入这个文件夹
    split_seq_each_contig_a_file.py -i Sgun_curated_v1.1.fasta  -o seq_file
    ''',formatter_class=RawTextHelpFormatter)


parser.add_argument('-i',
                help='输入的fasta文件')


parser.add_argument('-o',
                help='输出的文件夹')


args = parser.parse_args()


if not args.i or not args.o:
    parser.print_help()
    sys.exit()

infile =args.i
outpath = args.o



try:
	shutil.rmtree(outpath)
except:
	pass


try:
	os.mkdir(outpath)
except:
	pass


for i in SeqIO.parse(infile,'fasta'):
	with open(outpath+'/'+str(i.name)+'.fa','w') as fila:
		fila.write('>'+i.name+'\n')
		fila.write(str(i.seq)+'\n')
